package com.example.task1.ui.AllService.bus;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.task1.R;
import com.example.task1.application.MyApplication;
import com.example.task1.base.BaseActivity;
import com.example.task1.bean.BusPathBean;
import com.example.task1.bean.BusPathDetailsBean;
import com.example.task1.http.Api;
import com.example.task1.util.ApiResp;
import com.example.task1.util.CallBack;

import java.util.List;

import retrofit2.Call;

public class BusActivity extends BaseActivity {

    private RecyclerView rvList;
    private Button btnOrder;
    private BusAdapter busAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_bus);
        initView();
        initData();
        setAdapter();
        btnOrder.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MyApplication.intent(BusActivity.this,BusOrderActivity.class);
            }
        });
    }

    private void setAdapter() {
        busAdapter = new BusAdapter(this);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        rvList.setLayoutManager(linearLayoutManager);
        rvList.setAdapter(busAdapter);
    }

    private void initData() {
        Call<ApiResp> apiRespCall = Api.api().get(MyApplication.TOKEN, "/prod-api/api/bus/line/list");
        Api.send(apiRespCall, BusPathBean.class, new CallBack<BusPathBean>() {
            @Override
            public void success(BusPathBean data) {
                busAdapter.setData(data.getRows());
            }

            @Override
            public void error(String msg) {

            }
        });
    }


    @Override
    public String getMyTitle() {
        return "智慧交通";
    }

    private void initView() {
        rvList = (RecyclerView) findViewById(R.id.rv_list);
        btnOrder = (Button) findViewById(R.id.btn_order);
    }
}